

//  import {apiGet,apiPost,apiSubmit,apiBodyHeader,apiList} from "@/api/api-common.js";


import {request} from "axios";

export const apiList = (url, current, size, params) => {
  return apiGet(url,{current:current,size:size,...params});
}

export const apiDetail = (url,id) => {
  return apiGet(url,{id:id});
}


export const apiRemove = (url,ids) => {
  return apiPost(url,{ids:ids});
}




/**
 * 标准post参数请求
 * @param url
 * @param params
 */
export const apiPost = (url,params) => {
  return request({
    url: urlprocess(url),
    method: 'post',
    params: params||{}
  })
}

/**
 * 标准get参数请求
 * @param url
 * @param params
 */
export const apiGet = (url,params) => {
  return request({
    url: urlprocess(url),
    method: 'get',
    params: params||{}
  })
}
/**
 * post按body整体json提交
 * @param url
 * @param data
 */
 export const apiPostBody = (url,data) => {
  return request({
    url: urlprocess(url),
    method: 'post',
    data: data
  })
}

/**
 * post按body整体json提交
 * @param url
 * @param data
 */
export const apiSubmit = (url,data) => {
  return request({
    url: urlprocess(url),
    method: 'post',
    data: data
  })
}

/**
 * 请求头和请求体传数据
 * @param url
 * @param data
 * @param header
 */
export const apiBodyHeader = (url,data,header) => {
  return request({
    url: urlprocess(url),
    method: 'post',
    data: data,
    headers:{
      ...header
    }
  })
}





function urlprocess(url) {
  if(url.startsWith("/api/")||url.startsWith("api/")){
    alert("请去掉开头的api");
    return "";
  }
  if(url.startsWith("/")){//添加统一的api路径
    return "/api"+url;
  }else{
    return "/api/"+url;
  }
}
